<?php
/**
 * Отвечает за вывод элементов, общих для всех сущностей
 * 
 */
class View_Essence {
  /**
   * Вывести кнопку добавления/удаления из избранных
   *
   * @param int $id
   * @param int|string $type
   * @param bool $intStatus
   */
  public static function showToggleFavoriteBtn($id, $type, $intStatus) {
    $type = Service_Essence::getEssenceTypeID($type);    
    echo '<ul class="right_botron"><li><div id="favoriteEssence">';
      echo '<a class="link_make_favorite js_button" onclick="essence.toggleFavorite(this, ' . $id . ', ' . $type . ');return false;" href="#" id="makeFavoriteBtn"><span>' . ($intStatus ? 'Удалить из избранных' : 'Добавить в избранные') . '</span></a>';
		echo '</div></li></ul>';
  }
  
  public static function showAllEssencesFavorites($arrAllFavorites) {
    if (count($arrAllFavorites, COUNT_RECURSIVE) == 3) { //если в массиве только сами подмассивы-типы
      echo '<br />На данный момент Вы ничего не добавили в <strong>Избранное</strong>.';
      return false;
    }
    foreach ($arrAllFavorites as $typeId => $arrEssenceFavorites) {
      self::showEssenceFavorites($arrEssenceFavorites, $typeId);
    }
  }
  public static function showEssenceFavorites($arrEssenceFavorites, $essenceTypeId) {
    if (empty($arrEssenceFavorites))
      return false;
    echo '<div class="essenceFavorites">';
      echo '<h2>' . Service_Essence::getEssenceTypeHumanName($essenceTypeId, true) . '</h2>';
      switch ($essenceTypeId) {
        case 1:
          self::showArticlesListSimple($arrEssenceFavorites);
          break;
        case 7:
          self::displayLessonsSimple($arrEssenceFavorites);
          break;
        case 10:
          self::showSolutionsListSimple($arrEssenceFavorites);
          break;
        /*case 5:
          self::showQuestionListSimple($arrEssenceFavorites);
          break;*/
      }
    echo '</div>';
  }
  
  public static function showSolutionsListSimple($arrEssenceFavorites, $arrKs = NULL) {
    foreach ($arrEssenceFavorites as $arr) {
  		echo '
	    	<ul>';
  		if ($arrKs) {
  		  echo '<li class="last"><a class="anchor" href="#done-' . $arrKs[$arr['ID_user']] . '" title="">#<span>' . $arrKs[$arr['ID_user']] . '</span></a> </li>';
  		}
  		echo '
	    	  <li class="user"> <a href="' . W_ABSPATH . 'user/' . $arr['login'] . '/">' . $arr['login'] . '</a> | </li>
	    	  <li class="date">' . Service_Date::BDDateToHuman($arr['creation']) . '</li>
				  <li><a href="' . W_ABSPATH . 'solutions?idFolder=' . $arr['ID_folder'] . '&pageNum=1">' . $arr['folder_name'] . '</a></li>
					<li class="last"><a href="' . W_ABSPATH . 'solution/' . $arr['ID_solution'] . '/">' . $arr['solution_name'] . '</a></li>
					<li class="date">| ' . Service_Date::BDDateToHuman($arr['creation']) . '</li>
				</ul>';
    }
  }  
  public static function showArticlesListSimple($arrEssenceFavorites, $arrKs = NULL) {
	  foreach ($arrEssenceFavorites as $arr) {
      echo '
	    	<ul>';
  		if ($arrKs) {
  		  echo '<li class="last"><a class="anchor" href="#done-' . $arrKs[$arr['ID_user']] . '" title="">#<span>' . $arrKs[$arr['ID_user']] . '</span></a> </li>';
  		}
  		echo '
              <li class="user"> <a href="' . W_ABSPATH . 'user/' . $arr['login'] . '/">' . $arr['login'] . '</a> | </li>
				  		<li>';
					  		if ($arr['essence_type'] == 14)
						    	echo '<b><a href="' . W_ABSPATH . 'developerBlog">Блог разработчиков</a>';
								else 
									echo '<a href="' . W_ABSPATH . 'articles?idCommunity=' . $arr['ID_folder'] . '">' . $arr['folder_name'] . '</a>';
								echo '
							</li>
							<li class="last"><a href="' . W_ABSPATH . 'article/' . $arr['ID_article'] . '/">' . $arr['article_name'] . '</a>' . ($arr['essence_type'] == 14 ? '</b>' : NULL) . '</li>
							<li class="date">| ' . Service_Date::BDDateToHuman($arr['creation']) . '</li>
						</ul>';
		}
  }
  /*public static function showQuestionListSimple($arrQuestion){
		foreach ($arrQuestion as $arr){
			echo '
			<ul>
    	  <li class="user"> <a href="' . W_ABSPATH . 'user/' . $arr['login'] . '/">' . $arr['login'] . '</a> | </li>
				' . ($arr['show_folder'] == 0 ? '<li><a href="' . W_ABSPATH . 'questions?folder=' . $arr['ID_root_folder'] . '&pageNum=1">' . $arr['root_folder_name'] . '</a></li>' : NULL) . '
				<li><a href="' . W_ABSPATH . 'questions?folder=' . $arr['ID_folder'] . '&pageNum=1">' . $arr['folderName'] . ' </a></li>
				<li class="last"><a href="' . W_ABSPATH . 'question/' . $arr['ID_question'] . '">' . $arr['name'] . '</a></li>
				<li class="date">| ' . Service_Date::BDDateToHuman($arr['creation']) . '</li>
			</ul>';
		}
  }*/
  public static function displayLessonsSimple($arrLessons, $arrKs = NULL){
		foreach ($arrLessons as $arr) {
			echo '
	    	<ul>';
  		if ($arrKs) {
  		  echo '<li class="last"><a class="anchor" href="#done-' . $arrKs[$arr['ID_user']] . '" title="">#<span>' . $arrKs[$arr['ID_user']] . '</span></a> </li>';
  		}
  		echo '
				  <li class="user"> <a href="' . W_ABSPATH . 'user/' . $arr['login'] . '/">' . $arr['login'] . '</a> | </li>
					<li><a href="' . W_ABSPATH . 'tutorial/' . $arr['url_name'] . '">' . $arr['tutorial_name'] . '</a></li>
					<li><a href="' . W_ABSPATH . 'tutorial/' . $arr['url_name'] . '/theme/' . $arr['ID_tutorial_theme'] . '/1">' . $arr['theme_name'] . '</a></li>
					<li class="last"><a href="' . W_ABSPATH . 'tutorial/' . $arr['url_name'] . '/lesson/' . $arr['ID_tutorial_lesson'] . '">' . $arr['lesson_name'] . '</a></li>
					<li class="date">| ' . Service_Date::BDDateToHuman($arr['creation']) . '</li>
				</ul>';
		}
	 }
  
}
?>